import Vue from 'vue'
import vuex from 'vuex'
// import list from './list'
import shop from './shop'
import {getmsg} from '../api'
import goods from './goods'
import packages from './packages'
import message from './message'
import box from  './box'
Vue.use(vuex)

export default new vuex.Store({
    state: {
        arr:[]
    },
    mutations: {
        SETARR(state,payload){
            state.arr=payload
        },
        DELARR(state,payload){
            // console.log(payload);
            // console.log(1);
            let judeg = state.arr.find(item=>item.id===payload.id)
            if(judeg){
                judeg.inventory--
            }

        },
        DELATE_ARR(state,payload){
            let judge=state.arr.find(item=>item.id===payload.id)
            judge.inventory++
        }

    },
    getters: {
        
    },
    actions: {
        async GETMSG(context){
            await getmsg()
                .then(body=>body.json())
                .then(res=>{
                    console.log(res);
                    context.commit('SETARR',res.data)
                })            
        },
    },
    modules: {
        // list,
        shop,
        goods,
        packages,
        message,
        box
    },

})